Skip to content

Attempt to unblock blocked monitor updates on startup#4520

Open
TheBlueMatt wants to merge 2 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-03-startup-mpp-unblock
Open

Attempt to unblock blocked monitor updates on startup#4520
TheBlueMatt wants to merge 2 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-03-startup-mpp-unblock

Conversation

@TheBlueMatt
Copy link
Copy Markdown
Collaborator

When we make an MPP claim we push RAA blockers for each chanel to ensure we don't allow any single channel to make too much progress until all channels have the preimage durably on disk. We don't have to store those RAA blockers on disk in the ChannelManager as there's no point - if the ChannelManager gets to disk with the RAA blockers it also brought with it the pending ChannelMonitorUpdates that contain the preimages and will now be replayed, ensuring the preimage makes it to all ChannelMonitors.

However, just because those RAA blockers dissapear on reload doesn't mean the implications of them does too - if a later ChannelMonitorUpdate was blocked in the channel we don't have logic to unblock it on startup.

Here we add such logic, simply attempting to unblock all blocked ChannelMonitorUpdates that existed on startup.

Code written by Claude.

Fixes #4518

Needs a test, I have a start on one but need to clean it up

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Mar 30, 2026

👋 I see @tankyleo was un-assigned.
If you'd like another reviewer assignment, please click here.

@joostjager
Copy link
Copy Markdown
Contributor

There was a unit test already in issue linked in the description. On branch main...joostjager:2026-03-startup-mpp-unblock-with-test, it's added as a commit, and shows that your fix makes the test pass.

@joostjager
Copy link
Copy Markdown
Contributor

Discussed offline and improved unit test by ignoring some ignored read outs and 'loops until settled'.

When we make an MPP claim we push RAA blockers for each chanel to
ensure we don't allow any single channel to make too much progress
until all channels have the preimage durably on disk. We don't have
to store those RAA blockers on disk in the ChannelManager as
there's no point - if the ChannelManager gets to disk with the RAA
blockers it also brought with it the pending ChannelMonitorUpdates
that contain the preimages and will now be replayed, ensuring the
preimage makes it to all ChannelMonitors.

However, just because those RAA blockers dissapear on reload
doesn't mean the implications of them does too - if a later
ChannelMonitorUpdate was blocked in the channel we don't have logic
to unblock it on startup.

Here we add such logic, simply attempting to unblock all blocked
`ChannelMonitorUpdate`s that existed on startup.

Code written by Claude.

Fixes lightningdevkit#4518
@TheBlueMatt TheBlueMatt force-pushed the 2026-03-startup-mpp-unblock branch from a38acca to 6977e25 Compare May 6, 2026 20:38
@TheBlueMatt
Copy link
Copy Markdown
Collaborator Author

Thanks! Rebased and included the test.

@TheBlueMatt TheBlueMatt marked this pull request as ready for review May 6, 2026 20:38
@ldk-reviews-bot ldk-reviews-bot requested a review from joostjager May 6, 2026 20:39
@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented May 6, 2026

Good — takes msgs::UpdateFulfillHTLC by value, so the clone() in the test is needed and correct.

I've done a thorough review of the implementation and test. My prior review was correct — no issues found.

No issues found.

The implementation is correct:

  1. New BackgroundEvent::AttemptUnblockMonitorUpdates variant — all pattern matches across the codebase are exhaustive. The variant is never serialized (background events are hardcoded to count 0 at line 18223).

  2. Deserialization logic (lines 19471-19477) — correctly queued after MonitorUpdateRegeneratedOnStartup/MonitorUpdatesComplete events, ensuring preimage replays are processed first. Only triggers for channels with blocked_monitor_updates_pending() > 0.

  3. Event processing (lines 8803-8808)handle_monitor_update_release(counterparty_node_id, channel_id, None) safely gates on raa_monitor_updates_held(), which correctly checks both actions_blocking_raa_monitor_updates (empty on fresh startup) and pending_events for any ReleaseRAAChannelMonitorUpdate completion actions that may have been created during the same process_background_events pass. If a PaymentClaimed event with such an action exists, the blocked updates are held until the user processes it; otherwise they're released immediately.

  4. Assertion at line 9765AttemptUnblockMonitorUpdates { .. } => false is correct; this debug assertion checks for preimage replay events for the claiming channel.

  5. Test — comprehensive coverage of the full cycle: two-channel MPP claim with asymmetric monitor state on reload, verifying both the startup-released fulfill (channel A) and the event-completion-released fulfill (channel B).

@TheBlueMatt TheBlueMatt force-pushed the 2026-03-startup-mpp-unblock branch from 6977e25 to 52a0030 Compare May 6, 2026 21:01
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.14%. Comparing base (1d36f7b) to head (01d55dc).
⚠️ Report is 76 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4520      +/-   ##
==========================================
- Coverage   86.16%   86.14%   -0.03%     
==========================================
  Files         156      157       +1     
  Lines      108669   108958     +289     
  Branches   108669   108958     +289     
==========================================
+ Hits        93638    93857     +219     
- Misses      12420    12484      +64     
- Partials     2611     2617       +6     
Flag Coverage Δ
tests 86.14% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the fix is just a few lines, it is still hard to fully understand all the consequences. Buthandle_monitor_update_release called with None seems safe with its double-check, and it fixes the bug.

}

#[test]
fn test_mpp_claim_htlc_fulfills_unblocked_on_reload() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you picked the commit message from the first commit on my branch where the test was bug-reproducing ("verifies the bug leaves an htlc stuck"), and combined it with the final test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, tweaked the commit message. Looks like we didn't get a second reviewer on this so hit the button.

@ldk-reviews-bot
Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@joostjager
Copy link
Copy Markdown
Contributor

Additional verification of this PR: #4601

@ldk-reviews-bot ldk-reviews-bot requested a review from tankyleo May 12, 2026 13:02
@ldk-reviews-bot
Copy link
Copy Markdown

✅ Added second reviewer: @tankyleo

Add a characterization test for a claimed MPP payment whose
preimage monitor updates are only partially persisted before restart.
The test drives both channels through a held fee-update commitment
dance, claims with async monitor persistence, reloads one fresh and
one stale monitor, and verifies that we don't leave a sender-side
HTLC stuck after reconnect.
@TheBlueMatt TheBlueMatt force-pushed the 2026-03-startup-mpp-unblock branch from 52a0030 to 01d55dc Compare May 12, 2026 13:13
@tankyleo tankyleo requested review from valentinewallace and removed request for tankyleo May 12, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MPP claim HTLC fulfills stuck in holding cell after node restart

4 participants